package com.gthncz;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.gthncz.beans.LifeCircleBean;

public class BeanLifeCircleDemo {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		AbstractApplicationContext context = new ClassPathXmlApplicationContext("Beans_lifecircle.xml");
		LifeCircleBean lifeCircleBean = (LifeCircleBean) context.getBean("lifeCircleBean");
		System.out.println("Msg on main: " + lifeCircleBean.getMsg());
		// 需要注册一个在 AbstractApplicationContext 类中声明的关闭 hook 的 registerShutdownHook() 方法。它将确保正常关闭，并且调用相关的 destroy 方法。
		context.registerShutdownHook(); // 要使用 AbstractApplicationContext
	}

}
